/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utility;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 *
 * @author Jake
 */
public class SceneLoader {
    
    private Spatial sceneModel;
    private BulletAppState bulletAppState;
    private RigidBodyControl landscape;
    private CharacterControl player;
    private AssetManager assetManager;
    private CollisionShape sceneShape;
    private SimpleApplication app;
    
    public SceneLoader(AssetManager assetManager,SimpleApplication app, BulletAppState bulletAppState){
        this.assetManager = assetManager;
        this.app = app;
        this.bulletAppState = bulletAppState;
    }
    
    /**
     * Loads a scene from a zip file
     * @param fileLocation 
     *      location of the zip file
     * @param sceneName
     *      the name of the Scene to Load
     */
    public void setScene(String fileLocation, String sceneName){
        assetManager.registerLocator(fileLocation,ZipLocator.class.getName());
        sceneModel = assetManager.loadModel(sceneName);
        createNecessaries();
        
        
    }
    
    
    /**
     * Loading a precreated scene housed in the asset file location as opposed to a zip file
     * @param sceneName 
     *      the name of the scene
     */
    public void setScene(String sceneName){
        sceneModel = assetManager.loadModel(sceneName);
        createNecessaries();
        
    }
    
    /**
     * Creates all the necessary objects to detect and control collision with the terrain
     */
    private void createNecessaries(){
        sceneModel.setLocalScale(2f);
        sceneShape = CollisionShapeFactory.createMeshShape((Node)sceneModel);
        landscape = new RigidBodyControl(sceneShape,0);
        sceneModel.addControl(landscape);
        app.getRootNode().attachChild(sceneModel);
        bulletAppState.getPhysicsSpace().add(landscape);
    }
    
    /**
     * Creates the lighting system
     */
    private void setupLight(){
        
    }
    
}
